﻿#ifndef BPT_NODE_H
#define BPT_NODE_H

// 禁用断言
//#define NDEBUG

#include <stdio.h>
#include <assert.h>
#include "utils.h"

#define BPT_LEAF 1
#define BPT_INNER_NODE 2

class BPTNode {
	friend class BPTree;
protected:
	int size;	// 当前大小
	unsigned long* keys;
	
	BPTNode();
	virtual bool is_leaf();	//是否为叶子节点
	virtual void print();
	virtual bool spilled() = 0;	// 是否溢出，节点本身有多一个的冗余空间
	virtual bool concealed() = 0;	// 是否半满
	virtual bool concealed(int) = 0;
	virtual BPTNode* split(unsigned long&) = 0;	// 分裂溢出节点
	virtual bool remove(unsigned long) = 0;	//删除key
	virtual unsigned long borrow(BPTNode*, unsigned long, bool) = 0;	// 从兄弟节点借一个元素
	virtual void append(BPTNode*, unsigned long) = 0;
	virtual bool contain(unsigned long) = 0;
	/*序列化格式说明-按字节顺序
	* sizeof(int)			: 序列化长度
	* 1						: 标志字节
	* sizeof(int)			: size字段
	* sizeof(ulong)*size	: keys数组
	* remaining size		: 其他Leaf/InnerNode独有字段
	*/
	virtual char* serialize(int&) = 0;
	virtual bool load(char*) = 0;
	static BPTNode* deserialize(char*, int b, int c);
};

#endif // !BPT_NODE_H

